home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / msqc25t1 / popup.c < prev    next >
C/C++ Source or Header  |  1990-09-29  |  3KB  |  105 lines

  1. /* popup.c: Pop-up window library       */
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include <string.h>
  6. #include <graph.h>
  7. #include "textscrn.h"
  8. #include "popup.h"
  9.  
  10. void popShow (POPUP *pop)               /* display popup window */
  11. {
  12.     _setbordwindow (pop->top, pop->left,        /* create popup */
  13.                     pop->bottom, pop->right,
  14.                     pop->style, pop->normal, pop->normback);
  15.     _wrapon (_GWRAPOFF);                /* disable text wrap */
  16.     if (pop->text != NULL)
  17.         _outtext (pop->text);           /* write fixed text */
  18. }
  19.  
  20. void popKeep (POPUP *win)       /* preserve state of a window */
  21. {
  22.     win->lastcol = wherex();
  23.     win->lastrow = wherey();
  24. }
  25.  
  26. void popUse (POPUP *win)        /* re-anable existing window */
  27. {
  28.     _settextwindow (win->top, win->left, win->bottom, win->right);
  29.     _settextcolor (win->normal);
  30.     _setbkcolor (win->normback);
  31.     if (win->lastrow > 0)
  32.         _settextposition (win->lastrow, win->lastcol);
  33. }
  34.  
  35. void popCenter (POPUP *win, int row, char *string)
  36. {                                            /* Center string in window */
  37.     int i, tab;
  38.  
  39.     popUse (win);
  40.     tab = 1 + (win->right - win->left - strlen (string) + 1) /
  41.                             2; _settextposition (row, tab);
  42.     _outtext (string);
  43. }
  44.  
  45. void popRewrite (POPUP *win, int row, int fgcolor, int bgcolor)
  46. {                                /* Rewrite pop-up row with new colors */
  47.     int p, nchars, page, attrib;
  48.     union REGS reg;
  49.  
  50.         popUse (win);
  51.         page = _setactivepage (0);          /* which page? */
  52.         _setactivepage (page);
  53.         nchars = win->right - win->left + 1;    /* popup width */
  54.         attrib = (bgcolor << 4) - fgcolor;  /* new text attrib */
  55.         for (p = 1; p <= nchars; p++) {
  56.             _settextposition (row, p);
  57.             reg.h.ah = 8;                   /* get character */
  58.             reg.h.bh = page;                /* in active page */
  59.             int86 (0x10, ®, ®);           /* via ROM BIOS */
  60.             reg.h.ah = 9;               /* write back out with */
  61.             reg.h.bl = attrib;              /* hilite attribs */
  62.             reg.h.bh = page;
  63.             reg.x.cx = 1;                       /* one char */
  64.             int86 (0x10, ®, ®);
  65.         }
  66. }
  67.  
  68. void popHilite (POPUP *win, int row)
  69.         /* Hilight text in popup row */
  70. {
  71.     popRewrite (win, row, win->hilite, win->hiback);
  72. }
  73.  
  74. void popNormal (POPUP *win, int row)
  75.         /* Set text in popup row to normal attribs */
  76. {
  77.     popRewrite (win, row, win->normal, win->normback);
  78. }
  79.  
  80. void menubar (MENUBAR *spec)
  81.         /* Write the menu bar described by spec */
  82. {
  83.     int fore, back, p, s, row, col, c = 0;
  84.  
  85.     fore = _settextcolor (spec->fore);      /* get/set colors */
  86.     back = _setbkcolor (spec->back);
  87.     row = wherey();                         /* get cursor position */
  88.     col = wherex();
  89.     _settextposition (spec->row, 1);    /* start of menu bar */
  90.     for (s = 1; s < maxcol(); s++)
  91.         _outch (' ');                   /* set bar background */
  92.     _settextposition (wherey(), 1);     /* start text to bar */
  93.     for (p =0; spec->choice [p]; p++)   /* copy text to bar */
  94.         if (spec->choice [p] != '\n')
  95.             _outch (spec->choice [p]);      /* write char */
  96.         else                            /* else move to next menu item */
  97.             _settextposition (wherey(), spec->interval * ++c);
  98.  
  99.         /* Restore previous state */
  100.         _settextcolor (fore);           /* color scheme */
  101.         _setbkcolor (back);
  102.         _settextposition (row, col);    /* cursor position */
  103. }
  104.  
  105.